<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of EaExcelPrinter
 *
 * @author EaDeveloper
 */
class EaHtml2PdfPrinter implements EasoftPrinter {

    public static $ORIENTACION = "L";
    public static $PAPER = "a4";
    public static $PORTRAIT = "P";
    public static $LANDSCAPE = "L";
    public static $TAMA_FONT = 9;

    public function write($report) {
        // create new PDF document
        $doc = new EasoftHtml2PDFDoc(EaHtml2PdfPrinter::$ORIENTACION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'UTF-8', true);
        $doc->parent = $report;
        // set default file name to download
        $doc->fillMe();
        $doc->Output('reporte.pdf', 'D');
    }

}

class EasoftHtml2PDFDoc extends TCPDF {

    public $parent;

    public function setFileInfo() {
        $report = $this->parent;
        // set document information
        $this->SetCreator('EA-SOFTWARE');
        $this->SetAuthor('EaSoftCollegev3');
        $this->SetTitle($report->label);
        $this->SetSubject($report->subtitle);
        $this->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $report->label, "CINDE");
    }

    public function fillMe() {
        $this->setFileInfo();

        $this->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $this->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        $this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        $this->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $this->SetHeaderMargin(PDF_MARGIN_HEADER);
        $this->SetFooterMargin(PDF_MARGIN_FOOTER);
        $this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        $this->setImageScale(PDF_IMAGE_SCALE_RATIO);
        $this->SetFont('dejavusans', '', 10);
        $this->AddPage();
        $this->writeHTML($this->parent->show(true), true, false, true, false, '');
        $this->lastPage();
    }

}

?>